﻿using Kanban.IDal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace Kanban.BLL
{
    public abstract class BaseService<T> where T : class, new()
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        protected BaseService()
        {
            //执行给当前的 CurrentDal 赋值
            //强迫子类给当前类的 CurrentDal 属性赋值
            SetCurrentDal();
        }
        public IBaseDAL<T> Dal { get; set; }
        public abstract void SetCurrentDal();

        public Task<int> AddAsync(T entity)
        {
            return Dal.AddAsync(entity);
        }

        public Task<bool> DeleteAsync(int id)
        {
            return Dal.DeleteAsync(id);
        }

        public Task<bool> DeleteAsync(string ids)
        {
            return Dal.DeleteAsync(ids);
        }

        public async Task<int> UpdateAsync(T entity)
        {
            return await Dal.UpdateAsync(entity);
        }

        public Task<T> GetModelAsync(int id)
        {
            return Dal.GetModelAsync(id);
        }       

        public async Task<Tuple<IList<object>, int>> GetModelsByPageAsync(string column, string where, string orderby, int pageSize, int pageIndex)
        {
            return await Dal.GetModelsByPageAsync(column, where, orderby, pageSize, pageIndex);
        }
    }
}
